#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <mach/platform.h>

#define DRAVER_NAME "uevent_dev"
struct task_struct *uevent_task;

static uevent_thread(void *data)
{
	struct platform_device *u_dev = (struct platform_device *)data;

	while(1) {
		char            *configured[2];
		char            buf[32];
		static struct   timeval time_now;
		u64             tmiestamp;

		do_gettimeofday(&time_now);
		tmiestamp = (u64)time_now.tv_sec * 1000000 + time_now.tv_usec;

		snprintf(buf, sizeof(buf), "UEVENT_STATE=TRIGER[%lld]", tmiestamp);
		configured[0] = buf;
		configured[1] = NULL;

		kobject_uevent_env(&u_dev->dev.kobj, KOBJ_CHANGE, configured);
		/*kobject_uevent_env(&u_dev->dev.kobj, KOBJ_ADD, configured);*/

		udelay(1000*1000*2);
		/*printk("========= uevent send triger!!!\n");*/
	}
}

static int uevent_drv_probe(struct platform_device *pdev)
{
	uevent_task = kthread_run(uevent_thread, (void *)pdev, "uevent_thread");
}

static int __exit uevent_drv_remove(struct platform_device *pdev)
{
}

struct platform_device uevent_device = {
	.name = DRAVER_NAME,
};

static struct platform_driver uevent_driver = {
	.probe = uevent_drv_probe,
	.remove = __exit_p(uevent_drv_remove),
	.driver = {
		.name = DRAVER_NAME,
		.owner = THIS_MODULE,
	},
};

int __init simple_cdrv_init(void)
{
	int ret;

	platform_device_register(&uevent_device);
	platform_driver_register(&uevent_driver);

	return 0;
}

static void __exit simple_cdrv_exit(void)
{
	kthread_stop(uevent_task);
}
module_init(simple_cdrv_init);
module_exit(simple_cdrv_exit);
MODULE_LICENSE("GPL");
